﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Collections;
using System.Windows.Forms.DataVisualization.Charting;

namespace CarbonMeter
{
    public partial class ReportForm : Form
    {
        public ReportForm()
        {
            InitializeComponent();

        }

        private void ReportForm_Load(object sender, EventArgs e)
        {
            
           // chart1.Series["Series1"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
           /* foreach (object [] item in list)
            {

                chart1.Series["Series1"].Points.AddXY((DateTime)item[0], (double)item[1]);
            }*/
            comboBox1.SelectedIndex = 0;

            this.BringToFront();
            
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {

            updateDraw();

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            updateDraw();
        }
        String title = "Yıl";
        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rb = (RadioButton)sender;
            if (rb.Checked)
            {
                title = rb.Text;
            }

            updateDraw();
        }

        private void updateDraw()
        {
            string sel = comboBox1.SelectedItem.ToString();
            if (sel.StartsWith("Fosil"))
            {
                dataGridView20.DataSource = Database.getInstance().getFossilFuelConsumptionsForReport(title);
            }
            else if (sel.StartsWith("Nakliye"))
            {
                dataGridView20.DataSource = Database.getInstance().getNakliyeConsumptionsForReport();
            }
            else if (sel.StartsWith("Seyahat"))
            {
                dataGridView20.DataSource = Database.getInstance().getPeopleTransportationConsumptionsForReport();
            }

            Series series = chart1.Series["Karbon Salımı"];
            series.Points.Clear();
            series.XValueType = ChartValueType.Date;
            chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
            chart1.ChartAreas[0].AxisX.Title = title;
            
            if (title.Equals("Yıl"))
            {
                chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Years;
                chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Years;
                chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
            }
            else if (title.Equals("Ay"))
            {
                chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Months;
                chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
                chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 6;
            }
            else if (title.Equals("Hafta"))
            {
                chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Weeks;
                chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Weeks;
            }
            else if (title.Equals("Gün"))
            {
                chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Days;
                chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
                chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 120;
            }
            if (radioButton1.Checked)
            {

            }
            else if (radioButton2.Checked)
            {
                //carbonamount
                for (int i = 0; i < dataGridView20.Rows.Count; i++)
                {
                    DataGridViewRow row = dataGridView20.Rows[i];
                    series.Points.AddXY(row.Cells["billDate"].Value, row.Cells["carbonAmount"].Value);
                }
            }
        }
    }
}
